package com.example.demo.controller;

import com.example.demo.core.entity.RestResult;
import com.example.demo.core.utils.ResultUtil;
import com.example.demo.jobs.hbase.LisSynTest;
import com.example.demo.jobs.hbase.httptest;
import com.example.demo.service.DatabaseService;
import com.example.demo.service.DefaultDicMapService;
import com.example.demo.service.ElasticBulkService;

import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 直接从数据库抽取数据到ES api
 */
@RestController
@RequestMapping("/database/input")
@EnableAsync
public class DatabaseInputController {
    @Resource
    private DatabaseService databaseService;


    @RequestMapping("bulk/{theme}/{startdate}/{enddate}")
    public RestResult bulk(@PathVariable String theme,
                           @PathVariable String startdate,
                           @PathVariable String enddate) throws ParseException {
        databaseService.bulkBySql(theme, startdate, enddate, 0, false);

        return ResultUtil.success();
    }

    /**
     * 抽取新HIS库数据 api   bulknew/{theme}/{startdate}/{enddate}
     * @param theme
     * @param startdate
     * @param enddate
     * @return
     * @throws ParseException
     */
    @RequestMapping("bulknew/{theme}/{startdate}/{enddate}")
    public RestResult bulkNewHis(@PathVariable String theme,
                           @PathVariable String startdate,
                           @PathVariable String enddate) throws ParseException {
        databaseService.bulkBySql(theme,startdate, enddate, 0, true);

        return ResultUtil.success();
    }


//    @RequestMapping("bulknewall/{startdate}/{enddate}")
//    public RestResult bulkNewAllHis(@PathVariable String startdate,
//                                 @PathVariable String enddate) throws ParseException {
//        databaseService.bulkBySql(theme,startdate, enddate, 0, true);
//
//        return ResultUtil.success();
//    }

    @RequestMapping("bulktest/{theme}/{startdate}/{enddate}")
    public RestResult bulkTest(@PathVariable String theme,
                           @PathVariable String startdate,
                           @PathVariable String enddate) throws ParseException {
        databaseService.bulkBySql(theme,startdate, enddate, 10, false);

        return ResultUtil.success();
    }

//    @RequestMapping("bulk/{theme}")
//    public RestResult bulk() {
//        List<Map<String, Object>> datas = getDataByDataBases();
//    }
//
//    /**
//     * 从数据库获取数据
//     * @return
//     */
//    private List<Map<String, Object>> getDataByDataBases() {
//
//    }
}
